package fr.cephb.socialsnp.webapp.form;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import fr.cephb.sql.SQLUtilities;

public abstract class SQLValidator extends AbstractValidator<DataSource>
	{
	protected SQLValidator(DataSource dataSource)
		{
		super(dataSource);
		}
	
	@Override
	public void validate(FormParam param)
		{
		Connection con=null;
		try {
			con= getValue().getConnection();
			validate(con,param);
			} 
		catch (SQLException e) {
			throw new RuntimeException(e);
			}
		finally
			{
			SQLUtilities.safeClose(con);
			}
		}
	
	protected abstract void validate(Connection con,FormParam param) throws java.sql.SQLException;
	}
